// Copyright (C) Kumo inc. and its affiliates.
// Author: Jeff.li lijippy@163.com
// All rights reserved.
// This program is free software: you can redistribute it and/or modify
// it under the terms of the GNU Affero General Public License as published
// by the Free Software Foundation, either version 3 of the License, or
// (at your option) any later version.
//
// This program is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
// GNU Affero General Public License for more details.
//
// You should have received a copy of the GNU Affero General Public License
// along with this program.  If not, see <https://www.gnu.org/licenses/>.
//


#pragma once

#include <cstdint>
#include <optional>
#include <string>

namespace kumo::pollux::exec::trace {
    /// Defines the shared constants used by query trace implementation.
    struct TraceTraits {
        static inline const std::string kPlanNodeKey = "planNode";
        static inline const std::string kQueryConfigKey = "queryConfig";
        static inline const std::string kConnectorPropertiesKey =
                "connectorProperties";

        static inline const std::string kTaskMetaFileName = "task_trace_meta.json";
    };

    struct OperatorTraceTraits {
        static inline const std::string kSummaryFileName = "op_trace_summary.json";
        static inline const std::string kInputFileName = "op_input_trace.data";
        static inline const std::string kSplitFileName = "op_split_trace.split";

        /// Keys for operator trace summary file.
        static inline const std::string kOpTypeKey = "opType";
        static inline const std::string kPeakMemoryKey = "peakMemory";
        static inline const std::string kInputRowsKey = "inputRows";
        static inline const std::string kInputBytesKey = "inputBytes";
        static inline const std::string kRawInputRowsKey = "rawInputRows";
        static inline const std::string kRawInputBytesKey = "rawInputBytes";
        static inline const std::string kNumSplitsKey = "numSplits";
    };

    /// Contains the summary of an operator trace.
    struct OperatorTraceSummary {
        std::string opType;
        /// The number of splits processed by a table scan operator, nullopt for the
        /// other operator types.
        std::optional<uint32_t> numSplits{std::nullopt};

        uint64_t inputRows{0};
        uint64_t inputBytes{0};
        uint64_t rawInputRows{0};
        uint64_t rawInputBytes{0};
        uint64_t peakMemory{0};

        std::string toString() const;
    };
} // namespace kumo::pollux::exec::trace
